package com.scm.converter;


import com.scm.common.utils.AmountUtils;
import com.scm.dto.resp.PurchasePageDo;
import com.scm.persist.model.purchase.ScmPurchase;
import org.apache.commons.compress.utils.Lists;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Comment：
 * @Author: 邹渺
 * @Date: 2024/3/24
 * @Time: 14:27
 */
public class PurchaseConverter {


    public static PurchasePageDo toPurchasePageDo(ScmPurchase scmPurchase) {
        if (scmPurchase == null) {
            return null;
        }
        PurchasePageDo purchasePageDo = new PurchasePageDo();
        purchasePageDo.setId(scmPurchase.getId());
        purchasePageDo.setPurchaseOrderNumber(scmPurchase.getPurchaseOrderNumber());
        purchasePageDo.setPurchaseOrderState(scmPurchase.getPurchaseOrderState());
        purchasePageDo.setPurchaseOrderApprovalStatus(scmPurchase.getPurchaseOrderApprovalStatus());
        purchasePageDo.setPurchaseOrderType(scmPurchase.getPurchaseOrderType());
        purchasePageDo.setPurchasingUnit(scmPurchase.getPurchasingUnit());
        purchasePageDo.setPurchasingPeople(scmPurchase.getPurchasingPeople());
        purchasePageDo.setAmountStr(AmountUtils.fenToStr(scmPurchase.getAmount()));
        purchasePageDo.setPurchaseDateStr(scmPurchase.getPurchaseDateStr());
        // Not mapped ScmPurchase fields:
        // purchaseOrderApprovalRemarks
        // purchaseDate
        // purchaseDateStr
        // deliveryDate
        // deliveryDateStr
        // confirmTime
        // confirmTimeStr
        // amount
        // createTime
        // createUser
        // createUserId
        // updateTime
        // updateUser
        // updateUserId

        return purchasePageDo;
    }

    public static List<PurchasePageDo> convertScmOrdersToOrderPages(List<ScmPurchase> list) {

        List<PurchasePageDo> newlist = Lists.newArrayList();


        if(CollectionUtils.isEmpty(list)){
            return newlist;
        }

        list.forEach(a -> {
            newlist.add(toPurchasePageDo(a));
        });

        return newlist;

    }
}
